<?php
namespace User\Controller;
use Think\Controller;
/**
 * 会员中心
 */
class IndexController extends CkController {
    
    public function index(){
       $user= session("user");
       $data['uid']= de_crypt($user['id']);
       $data['user_info'] = M("user")->where(array('id'=>$data['uid']))->find();
       $data['user_info']['avatar'] = !empty($data['user_info']['avatar']) ? $data['user_info']['avatar']: "/Public/user/nopic.jpg";
       $jinri_time = strtotime(date('Y-m-d',time()));
       $where_jinri = array("uid"=>$data['uid'],"time"=>array('EGT',$jinri_time));
       $data['jinri_fx']= M("jifeiip_log")->field('SUM(price) as price')->where($where_jinri)->select(); //今日分享收益
       $data['jinri_fans']=M("jiakuan_xiaji_log")->field('SUM(price) as price')->where($where_jinri)->select(); //今日粉丝收益
       $where_jinri['type']=array("in","1,2,3,4,9");
       $data['jinri_order']=M("shop_order")->field('SUM(suk_ticheng) as ticheng')->where($where_jinri)->select();
       $data['tongzhi']=M("help")->where(array('type'=>2))->order("id desc")->select();
       $this->assign($data);
       $this->display();
    }
    

    //联系我们
    public function contact()
    {
       $this->display();
    }
    
    //关注我们
    public function about()
    {  
       $this->display();
    }

    //发展粉丝
    public function fans()
    {   
        $user= session("user");
        $data['uid']= $user['id'];
        $data['tg_url'] = U("/User/reg/".$data['uid'],'','',C("SITE_URL"));
        $this->assign($data);
        $this->display();
    }
   
    //排行榜
    public function user_top()
    {
        $data['user']=M("user")->field("balance,id,user_tel,nickname,paid,paid+balance as zonger")->order("paid+balance desc")->limit(30)->select();
        $this->assign($data);
        $this->display();
    }

    public function wallet()
    {
        $user= session("user");
        $data['uid']= de_crypt($user['id']);
        $data['user'] = M("user")->where(array('id'=>$data['uid']))->find();
        if(empty( $data['user']['avatar'])){
             $data['user']['avatar']="/Public/user/nopic.jpg";
        }
        $this->assign($data);
        $this->display();
    }

    //修改密码
    public function password()
    {   
        $data['title']="密码修改";
        $this->assign($data);
        $this->display();
    }
    
    //修改密码处理
    public function password_do()
    {
        $data=I('post.');
        if(empty($data['password']) || empty($data['password2'])){
            $this->error("密码不可以为空");
        }else{
            if($data['password']!==$data['password2']){
                $this->error("两次密码不一致");
            }
        }
       $user= session("user");
       $id= de_crypt($user['id']);
       $data2=array(
            "password"=>md5($data['password'])
         );
       if(M('user')->where(array('id'=>$id))->save($data2)!==false){
          $this->success("修改成功");
       }else{
          $this->error("修改失败,请联系管理员!");
       }
    }
    

    



}
